Skip to main content

Create Smart Account

In this guide, we will create a smart account and send a calldata using Axir's SDK and Node.js.

INFO

To have a better understanding of our SDK feel free to refer our Git repository.

1. Installation 🔨

First! Lets setup a Javascript/Typescript Project in your environment.

CAUTION

make sure you have NPM and Node Engine installed in your system.

Copy paste the below command in your preferred directory.

Terminal
mkdir axirwallet && cd axirwallet && npm init -y && npm i --save-dev @types/node tslib

Now its time to add our SDK! and viem 🐞

axirwallet
npm i @AxirWallet/SDK && npm i viem

2. Create a Smart Wallet 🔨

Please add a .env file in your project with this format.

PRIVATE_KEY = // your EOA private Key
RPC_URL = // your RPC URL

The PRIVATE_KEY will be added corresponding to a EOA Signer that will be added as a owner of the Smart Account. You can get get private keys of the EOA Signer from Wallets like Metamask, Coinbase, TrustWallet etc.

INFO

In the Ethereum Virtual Machine (EVM), smart contracts cannot initiate transactions by themselves. Instead, an external signer is required to induce state changes and initiate transactions within the EVM.

We highly suggest you use a dedicate RPC Service for your transactions. You can get RPCs from Infura, QuickNode, etc.

We use Pimlico Bundlers kindly sign in to Pimlico Dashboard and get your Bundler URL.

axirwallet/index.ts
import { AxirCore } from "axr-erc4337-sdk";

const smartWalletAccount = new AxirCore(
process.env.PRIVATE_KEY as Hex,
process.env.RPC_URL as String,
process.env.BUNDLER_URL as String,
BigInt(0) // salt you can enter any value
);

const { address } = await smartWalletAccount.getSenderAddress();
console.log("Axir Wallet Address is :", address);

Next run the Following Command:

npx ts-node index.ts

Then you should see your contrafactual Address in your terminal

Axir Wallet Address is : 0xC5779CaBaF94B5467a958A57E0Fd5bd71c45A976

Smart accounts are designed with a predetermined address that is known prior to deployment. Users can transfer funds to this address, and the actual deployment transaction is internally batched with the first transaction initiated by the smart account. Alternatively, Axir's Paymaster can be used to sponsor this transaction.

WARNING

Before proceeding, we need to fund our smart account address with some test network tokens. Since we are using the Sepolia network, go to the Sepolia Faucet, paste in your smart account address, and obtain some test tokens. Skipping this step might result in the AA21 didn't pay prefund error! 🚀